﻿@model ProductModel.ProductAttributeMappingModel
@{
    Layout = "";
    //page title
    ViewBag.Title = Loc["Admin.Catalog.Products.ProductAttributes.Attributes.ValidationRules"];

    var attributeControlType = Model.AttributeControlTypeId;
}
<form id="ProductAttributeValidationRulesPopup" asp-area="@Constants.AreaAdmin" asp-controller="Product" asp-action="ProductAttributeValidationRulesPopup" enctype="multipart/form-data" method="post"
      asp-route-ProductId="@HtmlExtensions.HtmlEncodeSafe(Context.Request.Query["ProductId"])"
      asp-route-btnId="@HtmlExtensions.HtmlEncodeSafe(Context.Request.Query["btnId"])"
      asp-route-formId="@HtmlExtensions.HtmlEncodeSafe(Context.Request.Query["formId"])">

    <div class="row">
        <div class="col-md-12">
            <div class="x_panel light form-fit">
                <div class="x_title">
                    <div class="caption">
                        <i class="fa fa-cubes"></i>
                        @Loc["Admin.Catalog.Products.ProductAttributes.Attributes.ValidationRules"]
                    </div>
                </div>
                <div class="x_content form">
                    <div class="form-horizontal">
                        <div class="form-body">
                            <div class="form-group" @(attributeControlType != AttributeControlType.TextBox && attributeControlType != AttributeControlType.MultilineTextbox ? Html.Raw("style='display: none;'") : null)>
                                <admin-label asp-for="ValidationMinLength" class="col-sm-3 control-label"/>
                                <div class="col-md-9 col-sm-9">
                                    <admin-input asp-for="ValidationMinLength"/>
                                    <span asp-validation-for="ValidationMinLength"></span>
                                </div>
                            </div>
                            <div class="form-group" @(attributeControlType != AttributeControlType.TextBox && attributeControlType != AttributeControlType.MultilineTextbox ? Html.Raw("style='display: none;'") : null)>
                                <admin-label asp-for="ValidationMaxLength" class="col-sm-3 control-label"/>
                                <div class="col-md-9 col-sm-9">
                                    <admin-input asp-for="ValidationMaxLength"/>
                                    <span asp-validation-for="ValidationMaxLength"></span>
                                </div>
                            </div>
                            <div class="form-group" @(attributeControlType != AttributeControlType.FileUpload ? Html.Raw("style='display: none;'") : null)>
                                <admin-label asp-for="ValidationFileAllowedExtensions" class="col-sm-3 control-label"/>
                                <div class="col-md-9 col-sm-9">
                                    <admin-input asp-for="ValidationFileAllowedExtensions"/>
                                    <span asp-validation-for="ValidationFileAllowedExtensions"></span>
                                </div>
                            </div>
                            <div class="form-group" @(attributeControlType != AttributeControlType.FileUpload ? Html.Raw("style='display: none;'") : null)>
                                <admin-label asp-for="ValidationFileMaximumSize" class="col-sm-3 control-label"/>
                                <div class="col-md-9 col-sm-9">
                                    <admin-input asp-for="ValidationFileMaximumSize"/>
                                    <span asp-validation-for="ValidationFileMaximumSize"></span>
                                </div>
                            </div>
                            <div class="form-group" @(attributeControlType != AttributeControlType.TextBox && attributeControlType != AttributeControlType.MultilineTextbox ? Html.Raw("style='display: none;'") : null)>
                                <admin-label asp-for="DefaultValue" class="col-sm-3 control-label"/>
                                <div class="col-md-9 col-sm-9">
                                    <admin-input asp-for="DefaultValue"/>
                                    <span asp-validation-for="DefaultValue"></span>
                                </div>
                            </div>
                            <div class="form-actions">
                                <div class="row">
                                    <div class="offset-sm-3 offset-md-3 col-md-9 col-sm-9">
                                        <button class="btn btn-success" type="submit" name="save">
                                            <i class="fa fa-check"></i> @Loc["Admin.Common.Save"]
                                        </button>
                                    </div>
                                </div>
                            </div>
                        </div>
                    </div>
                </div>
            </div>
        </div>
    </div>
    @if (!Model.ValidationRulesAllowed)
    {
        <div class="note note-danger">This attribute type cannot have validation rules</div>
    }
    <script>
        var mfp = $.magnificPopup.instance;
        $("#ProductAttributeValidationRulesPopup").submit(function (e) {
            e.preventDefault();
            var form = $(this);
            var url = form.attr('action');
            $.ajax({
                type: "POST",
                url: url,
                data: form.serialize(),
                success: function (data) {
                    if (data == "") {
                        mfp.close();
                        $('#btnRefreshProductAttributes').click();
                    } else {
                        $.magnificPopup.open({
                            items: {
                                src: data,
                                type: 'inline'
                            },
                            callbacks: {
                                open: function () {
                                    $('.mfp-wrap').removeAttr('tabindex');
                                }
                            }
                        });
                    }
                }
            });
        });
    </script>
</form>